package mutris.client.board;

import java.util.HashMap;
import java.util.Set;

public class BlockGroup {
	
	static public final BlockGroup SINGLE;
	static public final BlockGroup BAR;
	static public final BlockGroup STAIR_LEFT;
	static public final BlockGroup STAIR_RIGHT;
	
	static public final BlockGroup CUBE;
	
	static public final BlockGroup CHAIR_LEFT;
	static public final BlockGroup CHAIR_RIGHT;
	
	static public final BlockGroup PYRAMID;
	
	
	static {
		
		// single one block group
		SINGLE = new BlockGroup(1, 1);
		SINGLE.left = SINGLE.right = SINGLE;
		SINGLE.blocksMap.put(new BlockPoint(0, 0), Block.SINGLE);
		
		
		// bar block group
		BAR = new BlockGroup(4, 4);
		BlockGroup BAR_H = new BlockGroup(4, 4);
		for (int i=0; i<4; i++) {
			BAR_H.blocksMap.put(new BlockPoint(i, 1), Block.BAR);
			BAR.blocksMap.put(new BlockPoint(1, i), Block.BAR);
		}	
		BAR.left = BAR.right = BAR_H;
		BAR_H.left = BAR_H.right = BAR;

		
		// left stair block group
		STAIR_LEFT = new BlockGroup(3, 2);
		BlockGroup STAIR_LEFT_V = new BlockGroup(2, 3);
		
		STAIR_LEFT.blocksMap.put(new BlockPoint(0, 1), Block.STAIR_LEFT);
		STAIR_LEFT.blocksMap.put(new BlockPoint(1, 1), Block.STAIR_LEFT);
		STAIR_LEFT.blocksMap.put(new BlockPoint(1, 0), Block.STAIR_LEFT);
		STAIR_LEFT.blocksMap.put(new BlockPoint(2, 0), Block.STAIR_LEFT);

		STAIR_LEFT_V.blocksMap.put(new BlockPoint(0, 0), Block.STAIR_LEFT);
		STAIR_LEFT_V.blocksMap.put(new BlockPoint(0, 1), Block.STAIR_LEFT);
		STAIR_LEFT_V.blocksMap.put(new BlockPoint(1, 1), Block.STAIR_LEFT);
		STAIR_LEFT_V.blocksMap.put(new BlockPoint(1, 2), Block.STAIR_LEFT);

		STAIR_LEFT.left = STAIR_LEFT.right = STAIR_LEFT_V;
		STAIR_LEFT_V.left = STAIR_LEFT_V.right = STAIR_LEFT;

		
		// right stair block group
		STAIR_RIGHT = new BlockGroup(3, 2);
		BlockGroup STAIR_RIGHT_V = new BlockGroup(2, 3);
		
		STAIR_RIGHT.blocksMap.put(new BlockPoint(0, 0), Block.STAIR_RIGHT);
		STAIR_RIGHT.blocksMap.put(new BlockPoint(1, 0), Block.STAIR_RIGHT);
		STAIR_RIGHT.blocksMap.put(new BlockPoint(1, 1), Block.STAIR_RIGHT);
		STAIR_RIGHT.blocksMap.put(new BlockPoint(2, 1), Block.STAIR_RIGHT);

		STAIR_RIGHT_V.blocksMap.put(new BlockPoint(1, 0), Block.STAIR_RIGHT);
		STAIR_RIGHT_V.blocksMap.put(new BlockPoint(1, 1), Block.STAIR_RIGHT);
		STAIR_RIGHT_V.blocksMap.put(new BlockPoint(0, 1), Block.STAIR_RIGHT);
		STAIR_RIGHT_V.blocksMap.put(new BlockPoint(0, 2), Block.STAIR_RIGHT);

		STAIR_RIGHT.left = STAIR_RIGHT.right = STAIR_RIGHT_V;
		STAIR_RIGHT_V.left = STAIR_RIGHT_V.right = STAIR_RIGHT;
		
		
		// Cube
		CUBE = new BlockGroup(2, 2);
		CUBE.blocksMap.put(new BlockPoint(0, 0), Block.CUBE);
		CUBE.blocksMap.put(new BlockPoint(1, 0), Block.CUBE);
		CUBE.blocksMap.put(new BlockPoint(1, 1), Block.CUBE);
		CUBE.blocksMap.put(new BlockPoint(0, 1), Block.CUBE);
		CUBE.left = CUBE.right = CUBE;
		
		
		// Chair left
		CHAIR_LEFT = new BlockGroup(3, 2);
		BlockGroup CHAIR_LEFT_VR = new BlockGroup(2, 3);
		BlockGroup CHAIR_LEFT_UD = new BlockGroup(3, 2);
		BlockGroup CHAIR_LEFT_VL = new BlockGroup(2, 3);
		
		CHAIR_LEFT.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT.blocksMap.put(new BlockPoint(0, 1), Block.CHAIR_LEFT);
		CHAIR_LEFT.blocksMap.put(new BlockPoint(1, 1), Block.CHAIR_LEFT);
		CHAIR_LEFT.blocksMap.put(new BlockPoint(2, 1), Block.CHAIR_LEFT);

		CHAIR_LEFT_VR.blocksMap.put(new BlockPoint(1, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_VR.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_VR.blocksMap.put(new BlockPoint(0, 1), Block.CHAIR_LEFT);
		CHAIR_LEFT_VR.blocksMap.put(new BlockPoint(0, 2), Block.CHAIR_LEFT);

		CHAIR_LEFT_UD.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_UD.blocksMap.put(new BlockPoint(1, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_UD.blocksMap.put(new BlockPoint(2, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_UD.blocksMap.put(new BlockPoint(2, 1), Block.CHAIR_LEFT);

		CHAIR_LEFT_VL.blocksMap.put(new BlockPoint(1, 0), Block.CHAIR_LEFT);
		CHAIR_LEFT_VL.blocksMap.put(new BlockPoint(1, 1), Block.CHAIR_LEFT);
		CHAIR_LEFT_VL.blocksMap.put(new BlockPoint(1, 2), Block.CHAIR_LEFT);
		CHAIR_LEFT_VL.blocksMap.put(new BlockPoint(0, 2), Block.CHAIR_LEFT);

		CHAIR_LEFT.left = CHAIR_LEFT_VL; CHAIR_LEFT.right = CHAIR_LEFT_VR;
		CHAIR_LEFT_VR.left = CHAIR_LEFT; CHAIR_LEFT_VR.right = CHAIR_LEFT_UD;
		CHAIR_LEFT_UD.left = CHAIR_LEFT_VR; CHAIR_LEFT_UD.right = CHAIR_LEFT_VL;
		CHAIR_LEFT_VL.left = CHAIR_LEFT_UD; CHAIR_LEFT_VL.right = CHAIR_LEFT;

		
		// Chair right
		CHAIR_RIGHT = new BlockGroup(3, 2);
		BlockGroup CHAIR_RIGHT_VR = new BlockGroup(2, 3);
		BlockGroup CHAIR_RIGHT_UD = new BlockGroup(3, 2);
		BlockGroup CHAIR_RIGHT_VL = new BlockGroup(2, 3);
		
		CHAIR_RIGHT.blocksMap.put(new BlockPoint(0, 1), Block.CHAIR_RIGHT);
		CHAIR_RIGHT.blocksMap.put(new BlockPoint(1, 1), Block.CHAIR_RIGHT);
		CHAIR_RIGHT.blocksMap.put(new BlockPoint(2, 1), Block.CHAIR_RIGHT);
		CHAIR_RIGHT.blocksMap.put(new BlockPoint(2, 0), Block.CHAIR_RIGHT);

		CHAIR_RIGHT_VR.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VR.blocksMap.put(new BlockPoint(0, 1), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VR.blocksMap.put(new BlockPoint(0, 2), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VR.blocksMap.put(new BlockPoint(1, 2), Block.CHAIR_RIGHT);

		CHAIR_RIGHT_UD.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_UD.blocksMap.put(new BlockPoint(1, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_UD.blocksMap.put(new BlockPoint(2, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_UD.blocksMap.put(new BlockPoint(0, 1), Block.CHAIR_RIGHT);

		CHAIR_RIGHT_VL.blocksMap.put(new BlockPoint(0, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VL.blocksMap.put(new BlockPoint(1, 0), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VL.blocksMap.put(new BlockPoint(1, 1), Block.CHAIR_RIGHT);
		CHAIR_RIGHT_VL.blocksMap.put(new BlockPoint(1, 2), Block.CHAIR_RIGHT);

		CHAIR_RIGHT.left = CHAIR_RIGHT_VL; CHAIR_RIGHT.right = CHAIR_RIGHT_VR;
		CHAIR_RIGHT_VR.left = CHAIR_RIGHT; CHAIR_RIGHT_VR.right = CHAIR_RIGHT_UD;
		CHAIR_RIGHT_UD.left = CHAIR_RIGHT_VR; CHAIR_RIGHT_UD.right = CHAIR_RIGHT_VL;
		CHAIR_RIGHT_VL.left = CHAIR_RIGHT_UD; CHAIR_RIGHT_VL.right = CHAIR_RIGHT;

		
		// Pyramid
		PYRAMID = new BlockGroup(3, 2);
		BlockGroup PYRAMID_VR = new BlockGroup(3, 2);
		BlockGroup PYRAMID_UD = new BlockGroup(2, 3);
		BlockGroup PYRAMID_VL = new BlockGroup(3, 2);
		
		PYRAMID.blocksMap.put(new BlockPoint(1, 0), Block.PYRAMID);
		PYRAMID.blocksMap.put(new BlockPoint(0, 1), Block.PYRAMID);
		PYRAMID.blocksMap.put(new BlockPoint(1, 1), Block.PYRAMID);
		PYRAMID.blocksMap.put(new BlockPoint(2, 1), Block.PYRAMID);

		PYRAMID_VR.blocksMap.put(new BlockPoint(0, 0), Block.PYRAMID);
		PYRAMID_VR.blocksMap.put(new BlockPoint(0, 1), Block.PYRAMID);
		PYRAMID_VR.blocksMap.put(new BlockPoint(1, 1), Block.PYRAMID);
		PYRAMID_VR.blocksMap.put(new BlockPoint(0, 2), Block.PYRAMID);

		PYRAMID_UD.blocksMap.put(new BlockPoint(0, 0), Block.PYRAMID);
		PYRAMID_UD.blocksMap.put(new BlockPoint(1, 0), Block.PYRAMID);
		PYRAMID_UD.blocksMap.put(new BlockPoint(2, 0), Block.PYRAMID);
		PYRAMID_UD.blocksMap.put(new BlockPoint(1, 1), Block.PYRAMID);

		PYRAMID_VL.blocksMap.put(new BlockPoint(1, 0), Block.PYRAMID);
		PYRAMID_VL.blocksMap.put(new BlockPoint(1, 1), Block.PYRAMID);
		PYRAMID_VL.blocksMap.put(new BlockPoint(0, 1), Block.PYRAMID);
		PYRAMID_VL.blocksMap.put(new BlockPoint(1, 2), Block.PYRAMID);

		PYRAMID.left = PYRAMID_VL; PYRAMID.right = PYRAMID_VR;
		PYRAMID_VR.left = PYRAMID; PYRAMID_VR.right = PYRAMID_UD;
		PYRAMID_UD.left = PYRAMID_VR; PYRAMID_UD.right = PYRAMID_VL;
		PYRAMID_VL.left = PYRAMID_UD; PYRAMID_VL.right = PYRAMID;

	}
	
	
	
	
	private HashMap<BlockPoint,Block> blocksMap;
	private BlockGroup left;
	private BlockGroup right;
	
	private int relx;
	private int rely;
	
	private int width;
	private int height;
	
	
	private BlockGroup(int width, int height) {
		blocksMap = new HashMap<BlockPoint, Block>();
		this.width = width;
		this.height = height;
	}
	
	
	public int getRelativeX() {
		return relx;
	}
	
	public void setRelativeX(int x) {
		this.relx = x;
	}

	public int getRelativeY() {
		return rely;
	}
	
	public void setRelativeY(int y) {
		this.rely = y;
	}
	

	public Set<BlockPoint> getPoints() {
		return blocksMap.keySet();
	}
	
	public Block getBlock(BlockPoint p) {
		return blocksMap.get(p);
	}	
	
	
	public BlockGroup rotateRight() {
		return right;
	}
	
	public BlockGroup rotateLeft() {
		return left;
	}
	
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;		
	}
	
}
